import facade.AgriculturalSystemFacade;
import java.util.Scanner;

public class AgriculturalSystemConsole {
    private AgriculturalSystemFacade system;
    private Scanner scanner;

    public AgriculturalSystemConsole() {
        // 去掉 null 参数，调用无参构造函数
        system = new AgriculturalSystemFacade();
        scanner = new Scanner(System.in);
    }

    public void start() {
        while (true) {
            displayMenu();
            int choice = scanner.nextInt();
            scanner.nextLine(); // 消耗换行符
            handleChoice(choice);
        }
    }

    private void displayMenu() {
        System.out.println("农业机械智能控制系统 - 控制台版");
        System.out.println("1. 启动拖拉机");
        System.out.println("2. 停止拖拉机");
        System.out.println("3. 拖拉机规划路径");
        System.out.println("4. 启动收割机");
        System.out.println("5. 停止收割机");
        System.out.println("6. 收割机规划路径");
        System.out.println("7. 模拟警告事件");
        System.out.println("8. 模拟错误事件");
        System.out.println("9. 模拟紧急事件");
        System.out.println("10. 发送传感器数据");
        System.out.println("11. 查看拖拉机状态");
        System.out.println("12. 查看收割机状态");
        System.out.println("0. 退出");
        System.out.print("请输入你的选择: ");
    }

    private void handleChoice(int choice) {
        switch (choice) {
            case 1:
                system.startTractor();
                break;
            case 2:
                system.stopTractor();
                break;
            case 3:
                system.tractorPlanPath();
                break;
            case 4:
                system.startHarvester();
                break;
            case 5:
                system.stopHarvester();
                break;
            case 6:
                system.harvesterPlanPath();
                break;
            case 7:
                system.handleSystemEvent("warning");
                break;
            case 8:
                system.handleSystemEvent("error");
                break;
            case 9:
                system.handleSystemEvent("critical");
                break;
            case 10:
                System.out.print("请输入传感器数据: ");
                String sensorData = scanner.nextLine();
                system.simulateSensorData(sensorData);
                break;
            case 11:
                System.out.println("拖拉机状态: " + system.getTractorStatus());
                break;
            case 12:
                System.out.println("收割机状态: " + system.getHarvesterStatus());
                break;
            case 0:
                System.out.println("退出系统");
                System.exit(0);
            default:
                System.out.println("无效的选择，请重新输入");
        }
    }
}